<?php

namespace App\Http\Controllers\Api;

use App\Models\Message;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Symfony\Component\VarDumper\Cloner\Data;

use function PHPUnit\Framework\isEmpty;

class MessageController extends Controller
{
    //
    public function list()
    {
        //获取用户id
        $member_id= auth('api')->user()->id;
        // $member_id = 5;
        Message::where(['member_id' => $member_id])->update(['status' => 1]);
        $data = Message::where(['type' => 2, 'member_id' => $member_id])
            ->orWhere(['type' => 1])
            ->select('title', 'content', 'created_at')
            ->orderBy('created_at', 'desc')
            ->paginate();
        if($data->isEmpty()){
            return $this->success('暂时没有数据');
        }
        foreach ($data as $key => $value) {
            $res[] = [
                'title' => $value->title,
                'content' => $value->content,
                'created_at' => date('Y-m-d', strtotime($value->created_at)),
                'logo' => 'https://' . $_SERVER['SERVER_NAME'] . '/icon144.png'
            ];
        }
        return $this->success('ok', $res);
    }
}
